package com.gjy.jdk.util.concurrent.atomic;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-11 14:15:25
 */
public class AtomicIntegerTest {
    private static final Logger log = LoggerFactory.getLogger(AtomicIntegerTest.class);

    @Test
    public void test1() throws InterruptedException {
        AtomicInteger ai = new AtomicInteger(0);
        int processors = Runtime.getRuntime().availableProcessors();
        int maxProcessor = processors << 1;
        int queueProcessor = processors << 10;
        ThreadPoolExecutor pool = new ThreadPoolExecutor(processors, maxProcessor, 1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(queueProcessor));
        for (int i = 0; i < 10000; i++) {
            pool.submit(() -> {
                ai.incrementAndGet();
            });
        }
        TimeUnit.SECONDS.sleep(1);
        pool.shutdown();
        log.info("{}", ai.get());
    }

}
